<?php

namespace app\index\controller;

use app\common\controller\Frontend;

class Index extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    public function index()
    {
        return $this->view->fetch();
    }

    public function download(){
        $id = $this->request->get('id');
        $page = $this->request->get('page',1);
        $total = \think\Db::name('WorksPhoto')->where('works_catalog_id',$id)->count();
        $picArr = \think\Db::name('WorksPhoto')->where('works_catalog_id',$id)->order('weigh esc')->page($page,200)->select();
        if(empty($picArr)){
            die('无图片文件下载');
        }
        foreach ($picArr as $key => &$value) {
            //判断图片是否存在
            $value['url'] = cdnurl($value['image']);
            $value['name'] = $value['weigh'].'-'.basename($value['image']);
        }
        $this->assign('pic',json_encode($picArr));
        $this->assign('page',$page);
        $this->assign('id',$id);
        return $this->view->fetch();
    }
    public function download1(){
        $id = $this->request->get('id');
        $page = $this->request->get('page',1);
        $total = \think\Db::name('BroadcastImagePhoto')->where('broadcast_image_id',$id)->where('status',1)->count();
        $picArr = \think\Db::name('BroadcastImagePhoto')->where('broadcast_image_id',$id)->where('status',1)->page($page,200)->select();

        if(empty($picArr)){
            die('无图片文件下载');
        }
        foreach ($picArr as $key => &$value) {
            //判断图片是否存在
            $value['url'] = cdnurl($value['image']);
            $value['name'] = basename($value['image']);
        }
        $this->assign('pic',json_encode($picArr));
        $this->assign('page',$page);
        $this->assign('id',$id);
        return $this->view->fetch();
    }
    public function download3(){
        $id = $this->request->get('id');
        $page = $this->request->get('page',1);
        $row = \think\Db::name('BroadcastAi')->where('id',$id)->find();
        if($row['status'] != '2'){
            die('无图片文件下载');
        }
        if(empty($row['avatars'])){
            die('无图片文件下载');
        }
        $avatar = explode(',',$row['avatars']);
        $total = \think\Db::name('BroadcastImagePhoto')->alias('p')->join('__BROADCAST_IMAGE_AVATAR__ a ','a.photo_id = p.id')->where('p.broadcast_id',$row['broadcast_id'])->where('p.status',1)->where('a.avatar_id','in',$avatar)->count();
        $picArr = \think\Db::name('BroadcastImagePhoto')->alias('p')->join('__BROADCAST_IMAGE_AVATAR__ a ','a.photo_id = p.id')->where('p.broadcast_id',$row['broadcast_id'])->where('p.status',1)->where('a.avatar_id','in',$avatar)->field('p.image')->page($page,200)->select();

        if(empty($picArr)){
            die('无图片文件下载');
        }
        foreach ($picArr as $key => &$value) {
            //判断图片是否存在
            $value['url'] = cdnurl($value['image']);
            $value['name'] = basename($value['image']);
        }
        $this->assign('pic',json_encode($picArr));
        $this->assign('page',$page);
        $this->assign('id',$id);
        return $this->view->fetch();
    }
}